﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo06__滚动窗口绘图
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;

            g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);   //根据滚动条变换坐标

            Pen p = new Pen(Color.Red, 5);
            g.DrawEllipse(p, 120, 100, 150, 150);
            p.Dispose();
            g.Dispose();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            //当工作区小于 300×250 像素时显示滚动条
            this.AutoScrollMinSize = new Size(300, 300);
        }
    }
}
